using System;
using System.IO;
using System.Collections;

namespace XTCast.Radio {
	public class Radio:DictionaryBase {
		public static String NameAndVersion	{ get { return "XTCast.NET 1.0"; } }
		static public Config Config { get { return config; } }
		static public Radio Current { get { return radio; } }
		
		static private Config config;
		static private Radio radio;
		static Radio() {
			config=Config.GetConfig();
			radio=new Radio();
		}

		Radio() {
			Log.WriteLine(this, NameAndVersion + " starting...");
		}

		public Station GetStation(string host,string app) {
			foreach (LocationConfig loc in Config.Locations) {
				if (String.Compare(loc.Host,host,true)==0 && String.Compare(loc.Application,app,true)==0) {
					return GetStation(loc.Station);
				}
			}
			return null;
		}

		public override string ToString() {
			return "Radio";
		}

		public Station GetStation(string id) {
			Station s = (Station)Dictionary[id];
			if (s==null) {
				s = new Station(Config.GetStationConfig(id));
				Add(s);
			}
			return s;
		}

		public void Add(Station station) {
			lock (Dictionary.SyncRoot) {
				Dictionary[station.ID] = station;
			}
		}
	}
}